package com.fosdata.dpm.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fosdata.dpm.domain.SysXbdev;
import com.fosdata.dpm.services.mapper.SysXbdevMapper;
import com.fosdata.dpm.services.SysXbdevServices;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 * 箱变设备表 服务实现类
 * </p>
 *
 * @author gyk
 * @since 2025-10-22
 */
@Service
public class SysXbdevServicesImpl extends ServiceImpl<SysXbdevMapper, SysXbdev> implements SysXbdevServices {

    @Autowired
    private SysXbdevMapper sysXbdevMapper;

    @Override
    public SysXbdev getDevById(String devId) {
        try {
            return sysXbdevMapper.selectById(devId);
        }catch (Exception e){
            log.error(e.getMessage());
            return null;
        }
    }


    /**添加**/
    @Override
    public boolean addXbDev(SysXbdev sysXbdev){
        try {
            sysXbdevMapper.insert(sysXbdev);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    /**删除**/
    @Override
    public boolean deleteXbDev(String devId){
        try {
            sysXbdevMapper.deleteById(devId);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    /**更新**/
    @Override
    public boolean updateXbDev(SysXbdev sysXbdev){
        try {
            sysXbdevMapper.updateById(sysXbdev);
            return true;
        }catch (Exception e){
            log.error(e.getMessage());
            return false;
        }
    }

    //根据codeId获取箱变信息
    @Override
    public List<SysXbdev> getDevByDevType(String devType) {
        try {
            LambdaQueryWrapper<SysXbdev> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(SysXbdev::getXbdXb,devType).eq(SysXbdev::getXbdDelFlag,0);
            return sysXbdevMapper.selectList(queryWrapper);
        }catch (Exception e){
            log.error(e.getMessage());
            return null;
        }
    }


}
